#include <iostream>
#include <memory>
#include "TcpServer.hpp"
#include "Service.hpp"
#include "Net_Cal.hpp"

// ./calserver local-port
int main(int argc, char *argv[])
{
    if (argc != 2)
    {
        std::cout << "Usage: " << argv[0] << " local-port" << std::endl;
        exit(1);
    }

    uint16_t port = std::stoi(argv[1]);

    Net_Cal cal;
    Service svc(std::bind(&Net_Cal::Calculator, &cal, std::placeholders::_1));

    std::unique_ptr<TcpServer> tsvc = std::make_unique<TcpServer>(
        std::bind(&Service::IoService, &svc, std::placeholders::_1, std::placeholders::_2),
        port
    );

    tsvc->Loop();
    return 0;
}